package cn.lookup.mapper;

import cn.lookup.domain.Account;
import cn.lookup.domain.Order;
import cn.lookup.handler.DateHandler;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrderMapper {
    @Select("select *,a.id aid from orders o,account a where o.uid = a.id")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "order_time", property = "dateTime"),
            @Result(column = "total", property = "total"),
            @Result(column = "aid", property = "account.id"),
            @Result(column = "name", property = "account.name"),
            @Result(column = "money", property = "account.money"),
            @Result(column = "birthday", property = "account.birthday", typeHandler = DateHandler.class)
    })
    public abstract List<Order> queryAllOrderAndAccount();
    @Select("select * from orders")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "order_time",property = "dateTime"),
            @Result(column = "total",property = "total"),
            @Result(javaType = Account.class,property = "account",column = "uid",one = @One(select = "cn.lookup.mapper.AccountMapper.queryAccountById"))
    })
    public abstract List<Order> queryAllOrderAndAccount2();
    @Select("select * from orders where uid = #{uid}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "order_time",property = "dateTime"),
            @Result(column = "total",property = "total"),
    })
    public abstract List<Order> queryAllOrderByUid(int uid);
}
